<%--
    Document   : newcustomer
    Created on : Nov 24, 2011, 2:14:46 AM
    Author     : Venus
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.*,  Beans.LoaiKH,Beans.ThamSoHT,Models.ThamSoHT_Model,  Models.LoaiKH_Model, Models.KhachHang_Model"%>
<script type="text/javascript">
    function keypress(e){
        //Hàm dùng để ngăn người dùng nhập các ký tự khác ký tự số vào TextBox
        var keypressed = null;
        if (window.event)
        {
            keypressed = window.event.keyCode; //IE
        }
        else
        {
            keypressed = e.which; //NON-IE, Standard
        }
        if (keypressed < 48 || keypressed > 57 )
        { //CharCode của 0 là 48 (Theo bảng mã ASCII)
            //CharCode của 9 là 57 (Theo bảng mã ASCII)
            if (keypressed == 8 || keypressed == 127  )
            {//Phím Delete và Phím Back
                return;
            }
            return false;
        }
    }
</script>
<%
            int langid = (Integer) session.getAttribute("langid"); // ngôn ngữ hiện tại
            String dsts = " 'changemark', 'notice', 'order', 'enable', 'disable', 'all', 'status', 'rightmsg', 'checksubmitmsg', 'customer', 'createcustomer', 'nameofcustomer', 'customertype', 'mark', 'address', 'phonenumber', 'birthday', 'save', 'customerlist' ";
            ThamSoHT[] mdsts = ThamSoHT_Model.DSThamSo(dsts, langid); // mảng chứa các tham số của trang này.


            String all = mdsts[1].getTenTS();
            String changemark = mdsts[3].getTenTS();
            String customerlist = mdsts[7].getTenTS();
            String customertype = mdsts[8].getTenTS();
            String disable = mdsts[9].getTenTS();
            String enable = mdsts[10].getTenTS();
            String mark = mdsts[11].getTenTS();
            String nameofcustomer = mdsts[12].getTenTS();
            String notice = mdsts[13].getTenTS();
            String order = mdsts[14].getTenTS();
            String rightmsg = mdsts[16].getTenTS();
            String status = mdsts[18].getTenTS();

            String msgright = notice + "/" + rightmsg;            

            Vector vDSKH = (Vector) request.getAttribute("DSKH");
            Vector vDSLKH = (Vector) request.getAttribute("DSLKH");
            
            int numpage = 0;// khởi tạo số trang = 0
            int vsize = vDSKH.size();
            if (vsize % 6 == 0) // mỗi trang có 6 dòng
            {
                numpage = vsize / 6;
            } else {
                numpage = vsize / 6 + 1;
            }
            String xx = (String) request.getAttribute("item"); // trang hiện tại đang xem
            int item = Integer.parseInt(xx);
            String hoten = (String) request.getAttribute("hoten");
            String sodiem = (String) request.getAttribute("sodiem");
            String loaikh = (String) request.getAttribute("loaikh");
            String tinhtrang = (String) request.getAttribute("tinhtrang");
%>


    <div class="title">
            <%=customerlist%><a href="#" lang="<%=msgright%>" title="<%=changemark%>" onclick="DoiDiem(this.lang)" style=" float: right; " ><img style="height: 35px; width: 35px; margin-top: 3px; opacity: 0.8;" alt="" src="../images/doidiem1.png"></a>
        </div>
    <div class="content">
        <form name="dskh" action="">
            <table class="mytable" border="0" cellpadding="0" cellspacing="0">
                <thead>
                    <tr>
                        <th style="width: 9%;"><%=order%></th>
                        <th style=" width: 20%;">
                            <a href="#" id="titledskv1" style="margin-top: 5px;" class="down" lang="<%=msgright%>" name="1" onclick="SortSearchHoTenKH(this.name , this.className, this.lang)">
                                <div style="float:left"><%=nameofcustomer%></div>
                                <div style=" margin-right: 45px;" id="sortkv1" class="down1"></div>
                            </a>
                        </th>
                        <th style=" width: 22%;">
                            <a href="#" id="titledskv2" style="margin-top: 5px;" class="down" lang="<%=msgright%>" name="1" onclick="SortSearchDiemKH(this.name , this.className, this.lang)">
                                <div style="float:left"><%=mark%></div>
                                <div style=" margin-right: 45px;" id="sortkv2" class="down1"></div>
                            </a>
                        </th>
                        <th style=" width: 24%;">
                            <a href="#" id="titledskv3" style="margin-top: 5px;" class="down" lang="<%=msgright%>" name="1" onclick="SortSearchLoaiKH(this.name , this.className, this.lang)">
                                <div style="float:left"><%=customertype%></div>
                                <div style=" margin-right: 60px;" id="sortkv3" class="down1"></div>
                            </a>
                        </th>
                        <th style="margin-top: 2px; width: 20%;">
                            <a href="#" id="titledskv4" class="down" lang="<%=msgright%>" name="1" onclick="SortSearchTTKH(this.name , this.className, this.lang)">
                                <div><%=status%></div>
                                <div >
                                    <div id="sortkv4" class="down2"></div>
                                    <div id="sortkv4" class="up2" style="display:none;"></div>
                                </div>
                            </a>
                        </th>
                    </tr>
                    <tr id="searchKH" >
                        <th><img onclick="SearchCustomer( this.alt, this.lang)" lang="<%=msgright%>" style=" margin-top: 2px; margin-left: 3px; margin-bottom: -7px; cursor: pointer;"  alt="1" src="../images/search1.png"></th>
                        <th >
                            <input type="textbox" value="<%=hoten %>" style=" width: 120px;" class="hoten text" >
                        </th>
                        <th >
                            <input type="textbox" value="<%=sodiem %>" style=" width: 125px;" class="sodiem text"  onkeypress="return keypress(event)">
                        </th>
                        <th>
                            <select  lang="<%=msgright%>" id="1"  class="loaikh" onchange="SearchCustomer( this.id, this.lang)">
                                <%
                                    if(loaikh.equals("all")){%>
                                        <option value="all"><%=all%></option>
                                <%
                                    for(int i=0; i<vDSLKH.size(); i++){
                                        Beans.LoaiKH lkh = (Beans.LoaiKH) vDSLKH.elementAt(i);%>
                                        <option value="<%=lkh.getMaLKH() %>"><%=lkh.getTenLKH() %></option>
                                <%  }%>
                                <%  }
                                    else{%>
                                        <option value="<%=loaikh %>"><%=KhachHang_Model.LayTenLoaiKH(Integer.parseInt(loaikh), langid)%></option>
                                <%
                                    LoaiKH[] dsloaikh = LoaiKH_Model.DSLoaiKH(Integer.parseInt(loaikh), langid);
                                        for (int k = 0; k < dsloaikh.length; k++) {%>
                                <option value="<%=dsloaikh[k].getMaLKH() %>"><%=dsloaikh[k].getTenLKH() %></option>
                                <%  }%>
                                <%  }%>
                                <%
                                    if(!loaikh.equals("all")){%>
                                        <option value="all"><%=all%></option>
                                <%  }
                                %>                                
                            </select>
                        </th>
                        <th>
                            <select class="tinhtrang" id="1"  lang="<%=msgright%>" onchange="SearchCustomer( this.id, this.lang)">
                                <%
                                        if(tinhtrang.equals("1")){ %>
                                        <option value="1"><%=enable %></option>
                                        <option value="0"><%=disable %></option>
                                        <option value="all"><%=all %></option>
                                    <%    }
                                        else if(tinhtrang.equals("0")){%>
                                        <option value="0"><%=disable %></option>
                                        <option value="1"><%=enable %></option>
                                        <option value="all"><%=all %></option>
                                    <%  }
                                        else{%>
                                        <option value="all"><%= all %></option>
                                        <option value="1"><%=enable %></option>
                                        <option value="0"><%=disable %></option>
                                    <%    }
                                    %>
                            </select>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <%
                        for (int i = (item - 1) * 6; i < (item - 1) * 6 + 6 && i < vsize; i++) {
                            Beans.KhachHang kh = (Beans.KhachHang) vDSKH.elementAt(i);
                    %>
                    <tr>
                        <td class="STT"><%= i + 1%></td>
                        <td><a href="#" name="<%=kh.getMaKH()%>" lang="<%=msgright%>" onclick="UpdateDetailKH( this.name, this.lang)"><%=kh.getHoTen()%></a></td>
                        <td><%=kh.getDiemTL() %></td>
                        <td>
                            <select  class="<%= kh.getMaKH()  %>" lang="<%=msgright%>" onchange="UpdateLKH(this.value,  this.className, this.lang)">
                                <option value="<%=kh.getMaLKH() %>"><%=KhachHang_Model.LayTenLoaiKH(kh.getMaLKH(), langid)%></option>
                                <%
                                    LoaiKH[] dslkh = LoaiKH_Model.DSLoaiKH(kh.getMaLKH(), langid);
                                        for (int k = 0; k < dslkh.length; k++) {%>
                                <option value="<%=dslkh[k].getMaLKH() %>"><%=dslkh[k].getTenLKH() %></option>
                                <%  }
                                %>
                            </select>
                        </td>
                        <td>
                            <select  class="<%= kh.getMaKH()%>" lang="<%=msgright%>" onchange="UpdateStatusKH(this.value,  this.className, this.lang)">
                                <%
                                    if (kh.getTinhTrang() == 1) {%>
                                        <option value="1"><%= enable%></option>
                                        <option value="0"><%= disable%></option>
                                <%  } else {%>
                                        <option value="0"><%= disable%></option>
                                        <option value="1"><%= enable%></option>
                                <%  }
                                %>
                            </select>
                        </td>
                    </tr>
                    <%  }
                    %>
                </tbody>
            </table>
            <div class="pagination">
                <%
                    int trang = 1;
                    if (item > 1) {
                        trang = item - 1;
                    }
                %>
                <%
                    if (vsize > 6) {%>
                        <a href="#" class="prev" lang="<%=msgright%>"  name="<%= trang%>" onclick="SearchCustomer(this.name, this.lang)">«</a>
                <%  for (int c = 1; c <= numpage; c++) {
                        if (c != item) {
                %>          <a href="#" lang="<%=msgright%>" name="<%= c%>" onclick="SearchCustomer(this.name, this.lang)" ><%= c%></a>
                <%      } else {%><a class="current"> <%= c%></a> <% }
                    }
                %>
                <%
                    if (item + 1 <= numpage) {
                        trang = item + 1;
                    } else {
                        trang = item;
                    }
                %>  <a href="#" class="next" lang="<%=msgright%>" name="<%= trang%>" onclick="SearchCustomer(this.name, this.lang)">»</a>
                <%  }
                %>
            </div>
        </form>
    </div>
